﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.ComponentModel;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
	[Serializable, AttributeUsage(AttributeTargets.Property)]
	public class RecordPropertyChangeAttribute : GenericAttributeString, IReadableAttribute
	{
		public readonly static string DefaultChangeTrackerPropertyName = "ChangeTracker";
		public string ChangeTrackerPropertyName { get { return Val; } }

		public RecordPropertyChangeAttribute() : base(DefaultChangeTrackerPropertyName) { }
		public RecordPropertyChangeAttribute(string propChangeTracker) : base(propChangeTracker) { }

		public IPropertyChangeTracker GetChangeTracker(object item, Type t)
		{
			PropertyDescriptor propDesc = TypeDescriptor.GetProperties(t)[ChangeTrackerPropertyName];
			return (propDesc != null) ? (propDesc.GetValue(item) as IPropertyChangeTracker) : null;
		}
	}
}

